package com.cheng.student.service;

import com.cheng.student.beans.Administrator;
import com.cheng.student.dao.mappers.AdministratorMapper;
import com.cheng.student.service.interfaces.AdministratorService;
import com.cheng.student.utils.SqlSessionGetter;
import org.apache.ibatis.session.SqlSession;

public class AdministratorServiceImpl
    implements AdministratorService
{
    public static void main(String[] args)
    {
        SqlSession sqlSession = SqlSessionGetter.getSqlSession();

        AdministratorMapper mapper = sqlSession.getMapper(AdministratorMapper.class);

        int i = mapper.changePassword("zhangsan", "123453", "123");

        System.out.println(i);
    }
    @Override
    public Administrator administratorLogin(String username, String password)
    {
        SqlSession sqlSession = SqlSessionGetter.getSqlSession();

        AdministratorMapper mapper = sqlSession.getMapper(AdministratorMapper.class);

        Administrator administrator = mapper.selectAdministrator(username, password);

        sqlSession.close();

        return administrator;
    }

    @Override
    public int changePassword(String username, String password, String newPassword)
    {
        SqlSession sqlSession = SqlSessionGetter.getSqlSession();

        AdministratorMapper mapper = sqlSession.getMapper(AdministratorMapper.class);

        int i = mapper.changePassword(username, password, newPassword);

        sqlSession.close();
        return i;
    }
}
